#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 100;
const int M = 1e9+7;

int t;
ll n2, n3, n4;

int main()
{
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0);
    cin >> t;
    while(t--) {
        cin >> n2 >> n3 >> n4;
        ll m1 = n2, m2 = n4, m3 = n3/2;

        ll res = 0, d = 0;
        // 2, 3
        if (m2 > 0 && m3 > 0) {
            d = min(m2, m3);
            res += d, m2 -= d, m3 -= d;
        }

        // 3 1 1 
        if (m3 > 0 && m1 > 1) {
            d = min(m3, m1/2);
            res += d, m3 -= d, m1 -= d*2;
        }

        // 2 2 1
        if (m2 > 1 && m1 > 0) {
            d = min(m2/2, m1);
            res += d, m2 -= d*2, m1 -= d;
        }

        // 2 1 1 1
        if (m2 > 0 && m1 > 2) {
            d = min(m2, m1/3);
            res += d, m2 -= d, m1 -= d*3;
        }

        // 1*5
        if (m1 > 4) {
            d = m1/5;
            res += d, m1 -= d*5;
        }
        cout << res << endl;
    }
    return 0;
}